package com.fyb.basic.demo;

/**
 * @Author：MR.FANG
 * @name：SingleDemo
 */
public class SingleDemo {

    private volatile static SingleDemo uniqueInstance;

    private SingleDemo() {
    }

    public  static SingleDemo getUniqueInstance() {
        //先判断对象是否已经实例过，没有实例化过才进入加锁代码
        if (uniqueInstance == null) {
            //类对象加锁
            synchronized (SingleDemo.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new SingleDemo();
                }
            }
        }
        return uniqueInstance;
    }
}
